package es.onlysolutions.gs.comm.dao.hb;

import es.onlysolutions.arq.core.accesobd.GenericHbDao;
import es.onlysolutions.gs.comm.entity.User;
import es.onlysolutions.gs.comm.entity.Video;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

/**
 * Hibernate dao for video entities.
 */
public class VideoHbDao extends GenericHbDao
{

    /**
     * Get a video entity from the database with the user and youtube Id. null if it not exist.
     * @param youTubeId The you Tube id of the video.
     * @param user The user of the video.
     * @return The video or null.
     */
    public Video retrieveVideoById(String youTubeId, User user)
    {
        Criteria criteria = getCriteria( Video.class );
        criteria.add( Restrictions.eq("youTubeId", youTubeId) );
        criteria.add( Restrictions.eq("user", user) );
        return (Video) criteria.uniqueResult();
    }
}
